package com.itheima.appserver.controller;

import com.itheima.appserver.Service.UserInfoService;
import com.itheima.appserver.Service.UserService;
import com.itheima.appserver.config.NoAuthorization;
import com.itheima.commons.pojo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("/login")
    @NoAuthorization
    public ResponseEntity sendLoginMsg(@RequestBody Map<String, String> params) {
        //判断手机号是否符合要求，手机号正常的话一切运行正常，无需返回值，错误的话直接抛出
        userService.sendLoginMsg(params.get("phone"));
        //返回正常
        return ResponseEntity.ok(null);
    }

    //验证码是否正确，并且生成token
    @PostMapping("/loginVerification")
    @NoAuthorization
    public ResponseEntity userloginVerification(@RequestBody Map<String, String> params) {
        Map map = userService.loginVerification(params.get("phone"), params.get("verificationCode"));
        return ResponseEntity.ok(map);
    }


    /**
     * 完善个人信息
     *
     * @param params
     * @return
     */
    @PostMapping("loginReginfo")
    public ResponseEntity loginReginfo(@RequestBody Map<String, String> params) {
        userInfoService.loginReginfo(params);
        return ResponseEntity.ok(null);
    }


    /**
     * 头像上传/头像修改
     *
     * @param headPhoto
     * @return
     */
    @PostMapping("loginReginfo/head")
    public ResponseEntity loginReginfoHead(@RequestParam("headPhoto") MultipartFile headPhoto) {
        userInfoService.loginReginfoHead(headPhoto);
        return ResponseEntity.ok(null);
    }

}
